<html>
    <head>
        {php}html_header_show();{/php}
        <link rel="stylesheet" href="{php}echo $GLOBALS['css_header']; {/php}" type="text/css">
        <script type="text/javascript" src="{$WEBROOT}/library/js/jquery-1.2.2.min.js"></script>

        {literal}
        <style type="text/css" title="mystyles" media="all">
            .inactive {
                color:#777777;
            }
        </style>

        <script language="javascript">

            function changeLinkHref(id, addValue, value) {
                var myRegExp = new RegExp(":" + value + ":");
                if (addValue) { //add value to href
                    document.getElementById(id).href += ':' + value + ':';
                }
                else { //remove value from href
                    document.getElementById(id).href = document.getElementById(id).href.replace(myRegExp, '');
                }
            }

            function changeLinkHref_All(id, addValue, value) {
                var myRegExp = new RegExp(":" + value + ":");
                if (addValue) { //add value to href
                    document.getElementById(id).href += ':' + value + ':';
                }
                else { //remove value from href
                    document.getElementById(id).href = document.getElementById(id).href.replace(myRegExp, '');
                    // TajEmo Work By CB 2012/06/14 02:17:16 PM remove the target change 
                    //document.getElementById(id).target = '';
                }
            }

            function Check(chk) {
                var len = chk.length;
                if (len == undefined) {
                    chk.checked = true;
                }
                else {
                    for (pr = 0; pr < chk.length; pr++) {
                        if ($(chk[pr]).parents("tr.inactive").length == 0)
                        {
                            chk[pr].checked = true;
                            changeLinkHref_All('multiprint', true, chk[pr].value);
                            changeLinkHref_All('multiprintcss', true, chk[pr].value);
                            changeLinkHref_All('multiprintToFax', true, chk[pr].value);
                        }
                    }
                }
            }

            function Uncheck(chk) {
                var len = chk.length;
                if (len == undefined) {
                    chk.checked = false;
                }
                else {
                    for (pr = 0; pr < chk.length; pr++) {
                        chk[pr].checked = false;
                        changeLinkHref_All('multiprint', false, chk[pr].value);
                        changeLinkHref_All('multiprintcss', false, chk[pr].value);
                        changeLinkHref_All('multiprintToFax', false, chk[pr].value);
                    }
                }
            }

            var CheckForChecks = function(chk) {
                // Checks for any checked boxes, if none are found than an alert is raised and the link is killed
                if (Checking(chk) == false) {
                    return false;
                }
                return top.restoreSession();
            };

            function Checking(chk) {
                var len = chk.length;
                var foundone = false;

                if (len == undefined) {
                    if (chk.checked == true) {
                        foundone = true;
                    }
                }
                else {
                    for (pr = 0; pr < chk.length; pr++) {
                        if (chk[pr].checked == true) {
                            foundone = true;
                        }
                    }
                }
                if (foundone) {
                    return true;
                } else {
                    alert("{/literal}{xl t='Please select at least one prescription!'}{literal}");
                    return false;
                }
            }

            $(document).ready(function() {
                parent.$.fancybox.close();
                $(":checkbox:checked").each(function() {
                    changeLinkHref('multiprint', this.checked, this.value);
                    changeLinkHref('multiprintcss', this.checked, this.value);
                    changeLinkHref('multiprintToFax', this.checked, this.value);
                });
            })

        </script>

        {/literal}
    </head>
    <body class="body_top">

        {if $prescriptions}
        <span class="title"><b>{xl t='List'}</b></span>

        <div id="prescription_list">

            <form name="presc">

                <div id="print_links">
                    <table width="100%">
                        <tr>
                            <td align="left">
                                <table>
                                    <tr>
                                        <td>
                                            <a id="multiprint" href="{$CONTROLLER}prescription&multiprint&id={$printm}" onclick="top.restoreSession()" class="css_button"><span>{xl t='Print'} ({xl t='PDF'})</span></a>
                                        </td>
                                        <td>
                                            <!-- TajEmo work by CB 2012/06/14 02:16:32 PM target="_script" opens better -->
                                            <a target="_script" id="multiprintcss" href="{$CONTROLLER}prescription&multiprintcss&id={$printm}" onclick="top.restoreSession()" class="css_button"><span>{xl t='Print'} ({xl t='HTML'})</span></a>
                                        </td>
                                        <td style="border-style:none;">
                                            <a id="multiprintToFax" href="{$CONTROLLER}prescription&multiprintfax&id={$printm}" onclick="top.restoreSession()" class="css_button"><span>{xl t='Print'} ({xl t='Fax'})</span></a>
                                        </td>
                                        {if $CAMOS_FORM == true}
                                        <td>
                                            <a id="four_panel_rx" href="{$WEBROOT}/interface/forms/CAMOS/rx_print.php?sigline=plain" onclick="top.restoreSession()" class="css_button"><span>{xl t='Print Four Panel'}</span></a>
                                        </td>
                                        {/if}
                                    </tr>
                                </table>
                            </td>
                            <td align="right">
                                <table>
                                    <tr>
                                        <td>
                                            <a href="#" class="small" onClick="Check(document.presc.check_list);"><span>{xl t='Check All'}</span></a> |
                                            <a href="#" class="small" onClick="Uncheck(document.presc.check_list);"><span>{xl t='Clear All'}</span></a>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </div>


                <table width="100%" class="showborder_head" cellspacing="0px" cellpadding="2px">
                    <tr> 
                        <!-- TajEmo Changes 2012/06/14 02:01:43 PM by CB added Heading for checkbox column -->   
                        <th width="8px">&nbsp;</th>
                        <th width="8px">&nbsp;</th>
                        <th width="180px">{xl t='Drug'}</th>
                        <th>{xl t='Created'}<br />{xl t='Changed'}</th>
                        <th>{xl t='Dosage'}</th>
                        <th>{xl t='Qty'}.</th>
                        <th>{xl t='Unit'}</th>
                        <th>{xl t='Provider'}</th>
                    </tr>

                    {foreach from=$prescriptions item=prescription} 
                    <!-- TajEmo Changes 2012/06/14 02:03:17 PM by CB added cursor:pointer for easier user understanding -->  
                    <tr style="cursor:pointer" id="{$prescription->id}" class="showborder onescript {if $prescription->active <= 0} inactive{/if}" title="{xl t='Click to view/edit'}">
                        <td align="center"> 
                            <input class="check_list" id="check_list" type="checkbox" value="{$prescription->id}" {if $prescription->encounter == $prescription->get_encounter() && $prescription->active > 0}checked="checked" {/if}onclick="changeLinkHref('multiprint',this.checked, this.value);changeLinkHref('multiprintcss',this.checked, this.value);changeLinkHref('multiprintToFax',this.checked, this.value)" title="{xl t='Select for printing'}">
                        </td>
                        {if $prescription->erx_source==0}
                        <td class="editscript"  id="{$prescription->id}">
                            <a class='editscript css_button_small' id='{$prescription->id}' href="controller.php?prescription&edit&id={$prescription->id}" style="margin-top:-2px"><span>{xl t='Edit'}</span></a>
                            <!-- TajEmo Changes 2012/06/14 02:02:22 PM by CB commented out, to avoid duplicate display of drug name
                              {if $prescription->active > 0}<b>{/if}{$prescription->drug}{if $prescription->active > 0}</b>{/if}&nbsp;
                            --> 
                        </td>
                        <td class="editscript"  id="{$prescription->id}">
                            {if $prescription->active > 0}<b>{/if}{$prescription->drug}{if $prescription->active > 0}</b>{/if}&nbsp;
                        </td>
                        {else}
                        <td id="{$prescription->id}">
                            {if $prescription->active > 0}<b>{/if}{$prescription->drug}{if $prescription->active > 0}</b>{/if}&nbsp;
                        </td>
                        {/if}
                        <td id="{$prescription->id}">
                            {$prescription->date_added}<br />
                            {$prescription->date_modified}&nbsp;
                        </td>
                        <td id="{$prescription->id}">
                            {$prescription->get_dosage_display()} &nbsp;
                        </td>
                        {if $prescription->erx_source==0}
                        <td class="editscript" id="{$prescription->id}">
                            {$prescription->quantity} &nbsp;
                        </td>
                        {else}
                        <td id="{$prescription->id}">
                            {$prescription->quantity} &nbsp;
                        </td>
                        {/if}
                        <td id="{$prescription->id}">
                            {$prescription->get_size()} {$prescription->get_unit_display()}&nbsp;
                        </td>
                        <td id="{$prescription->id}">
                            {$prescription->provider->get_name_display()}&nbsp;
                        </td>
                    </tr>
                    {/foreach}
                </table>

            </form>
        </div>

        {else}
        <div class="text" style="margin-top:10px">{xl t='There are currently no prescriptions'}.</div>
        {/if}

    </body>
    {literal}
    <script language='JavaScript'>

            $(document).ready(function() {
                $("#multiprint").click(function() {
                    return CheckForChecks(document.presc.check_list);
                });
                $("#multiprintcss").click(function() {
                    return CheckForChecks(document.presc.check_list);
                });
                $("#multiprintToFax").click(function() {
                    return CheckForChecks(document.presc.check_list);
                });
                $(".editscript").click(function() {
                    ShowScript(this);
                });
                $(".onescript").mouseover(function() {
                    $(this).children().toggleClass("highlight");
                });
                $(".onescript").mouseout(function() {
                    $(this).children().toggleClass("highlight");
                });
            });

            var ShowScript = function(eObj) {
                top.restoreSession();
                objID = eObj.id;
                document.location.href = "{/literal}{$WEB_ROOT}{literal}/controller.php?prescription&edit&id=" + objID;
                return true;
            };

    </script>
    {/literal}
</html>